import Vue from 'vue'
import VueRouter from 'vue-router'
import HomeView from '../views/HomeView.vue'
import NotesView from '../views/NotesView.vue'
import UserView from "../views/UserView.vue";
import  SearchView from "../views/SearchView.vue";

Vue.use(VueRouter)

const routes = [
  { path: '/', redirect: '/home' },
  
  {
    path: '/home',
    name: 'home',
    component:HomeView
  },
  {
    path: '/note',
    name: 'note',
    component: NotesView,
  },
  {
    path: '/user',
    name: 'user',
    component: UserView,
  },
  {
    path: '/search',
    name: 'search',
    component:SearchView,
  },

  {
    path: '/noteitem',
    name: 'noteitem',
    component: () => import('../views/NoteitemView.vue')
  },
  {
    path: '/homeitem',
    name: 'homeitem',
    component: () => import('../views/HomeitemView.vue')
  },
  {
    path: '/searchitem',
    name: 'searchitem',
    component: () => import('../views/SearchitemView.vue')
  },
  {
    path: '/searchlist',
    name: 'searchlist',
    component: () => import('../views/SearchlistView.vue')
  },
  {
    path: '/useritem',
    name: 'useritem',
    component: () => import('../views/UseritemView.vue')
  },
  {
    path: '/writenote',
    name: 'writenote',
    component: () => import('../views/WritenoteView.vue')
  },
  {
    path: '/login',
    name: 'login',
    component: () => import('../views/LoginView.vue')
  },
  {
    path: '/upload',
    name: 'upload',
    component: () => import('../views/UploadnoteView.vue')
  },
  {
    path: '/myitem',
    name: 'myitem',
    component: () => import('../views/MyitemView.vue')
  },
]
// 注意:解决路由跳转问题
const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(location){
  return originalPush.call(this,location).catch(err=>err);
}

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes,
  scrollBehavior () {
    return { x: 0, y: 0 }
  }
})

export default router
